home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / MAILUP.SLT < prev    next >
Text File  |  1991-02-02  |  27KB  |  739 lines

  1. //-----------------------------------------------------------
  2. // MAILUP.SL? Automatic ASCII upload.
  3. //
  4. // Please look at the comments through the whole file, and modify to
  5. // suit your needs, BEFORE you use it. Then recompile with CS MAILUP.
  6.  
  7.  
  8. // Note: Lines commented out with //!! are not used in this script,
  9. // but in other, related ones. Please don't delete them; they may
  10. // become useful later.
  11. //-----------------------------------------------------------
  12.  
  13. int LIMIT = 999;                  // Max. no. of lines for messages.
  14.  
  15. str bbs_type  [32]                // BBS type.
  16.    ,codename   [8]                // This BBS's codename
  17.    ,maildir   [64] = ""           // Mail directory
  18.    ,input    [144]                // Input line.
  19.    ,input1   [144]                // Help line.
  20.    ,filespec  [64]                // File specification.
  21.    ,shortname [10]                // Shortened name for this BBS.
  22.    ,PrevConf  [20]                // Previous conference.
  23.    ,file      [64]                // Filename for upload.
  24.    ,allfiles [100]                // File *numbers* for upload.
  25.    ,command   [10]="Command:"     // Command prompt.
  26.    ,temp       [4]                // Short temporary string.
  27.                                   // For the Global storage:
  28.    ,global      []="GLOBAL"       // Global script.
  29.    ,join        []="JOINCONF"     // Join Conference script
  30.    ,bbstype     []="BTYPE"        // BBS type.
  31.    ,short       []="SHORT"        // Short BBS name.
  32.    ,code        []="CNAME"        // Codename for this BBS.
  33.    ,graph       []="GRAPH"        // Graphics
  34.    ,version     []="PCBVER"       // PCB version number
  35.    ,conf        []="CONF"         // Current conference.
  36.    ,prompt      []="PROMPT"       // Current command prompt.
  37.    ;     
  38.  
  39. int tol = 300                            // No activity for 30 sec.
  40.    ,stat, tmark                          // makes script time out. 
  41.    ,mbbs, pcb, rbbs, opus, fido, crcs 
  42.    ,PCBver                               // PCBoard version.
  43.    ,first
  44.    ,graphics
  45.    ;
  46.  
  47. //-----------------------------------------------------------   
  48. // Script starts here.
  49. //-----------------------------------------------------------   
  50.  
  51. main()
  52. {
  53. int c, i, j, k, l, m;
  54.  
  55.   update_term();                         // Update status bar. 
  56.  
  57. // Only if online.
  58.  
  59.   if (!carrier())  
  60.   { failtone();
  61.     status_wind ("THIS SCRIPT ONLY WORKS IF YOU'RE ONLINE!",20);
  62.     return (-1);
  63.   }
  64.  
  65.   read (bbstype,bbs_type);               // Get BBS type. 
  66.   read (short,shortname);                // Shortened BBS name.
  67.   read (conf,PrevConf);                  // Previous conference.
  68.   read (prompt,command);                 // Command prompt.
  69.  
  70.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  71.   if      (bbs_type == "MBBS") mbbs = 1;
  72.   else if (bbs_type == "PCB" )
  73.   { pcb = 1;
  74.     read (version,temp);
  75.     PCBver = stoi (temp);                // Get PCB version. 
  76.   }
  77.   else if (bbs_type == "RBBS") rbbs = 1;
  78.   else if (bbs_type == "OPUS") opus = 1;
  79.   else if (bbs_type == "FIDO") fido = 1;
  80.   else if (bbs_type == "CRCS") crcs = 1;
  81.   else                                          
  82.   { wrongBBS();                          // Doesn't match script!
  83.     return (-1);
  84.   }
  85.  
  86. // Search for the upload specifications.
  87.  
  88.   if (read (code,codename) <= 0)         // Get BBS ID-code.
  89.     codename = "MAIL";                   // Set default.
  90.   if (getenv ("XBOARD",maildir))         // Get XBoard dir.
  91.     get_id_code();                       // Get correct ID-code.
  92.   else if (m=fopen("XBOARD.DIR","r") >0) // Try open XBoard.DIR file.
  93.   { fgets (maildir,64,m);                // Read dir.name.
  94.     fclose (m);
  95.     get_id_code();
  96.   }
  97.   else
  98.     maildir = _up_dir;                   // If no XBoard, use MailDir.
  99.  
  100.   if (codename=="MAIL")
  101.     strcat (maildir,shortname);          // Use short name.
  102.   else
  103.     strcat (maildir,codename);           // Use codename.
  104.   strcat (maildir,"\");    
  105.  
  106.   filespec = maildir;                    // Get mail dir.
  107.   strcat (filespec,codename);            // Add codename again.
  108.   strcat (filespec,".m*");               // Add extension.
  109.   setchrs (allfiles,0,' ',100);          // Init. all files to 0.
  110.  
  111.   while (filefind(filespec,0,file))      // For each file found:
  112.   { filespec = "";               
  113.     k = strposi (file,".M",0);           // Find number.
  114.     setchrs(file,0,' ',k+2);
  115.     setchr (allfiles,stoi(file),'!');    // Mark this file number.
  116.   }
  117.  
  118.   while ((k=strposi(allfiles,"!",0)) > 0)// For each file found
  119.   { setchr (allfiles,k,' ');             // earlier:
  120.     itos (k,file);
  121.     filespec=codename;                   // Build name.
  122.     strcat(filespec,".M");
  123.     strcat(filespec,file);
  124.     message_up(filespec);                // Send message.
  125.   }
  126.   return(0);
  127. }
  128.  
  129. //-----------------------------------------------------------
  130. // Upload one message to the BBS.
  131. //-----------------------------------------------------------
  132.  
  133. message_up (str fname)
  134. {
  135. int f, i, l, lineno, FSE, again          // File handle etc.
  136.    ,RO, WT  
  137.    ,t1, t2, t3, t4, t5, t6, t7, t8, t11  // Variables for tracking.
  138.    ,SendOK
  139.    ,empty, hide, number
  140.    ;
  141. str fullname [64]                        // Full file name.
  142.    ,include  [64]                        // Include file name.
  143.    ,conf     [20]                        // Conference name.
  144.    ,towhom   [24]                        // To whom.
  145.    ,reply     [6]                        // Reply to which mess.number
  146.    ,subj     [26]                        // What subject?
  147.    ,echo      [4]                        // Echo to other BBSes?
  148.    ,priv      [4]                        // Private?
  149.    ,help      [6]                        // Help string
  150.    ,sline    [80]                        // Line read back from screen.
  151.    ,quote     [4]                        // Previous
  152.    ,nextq     [4]                        // and next quote.
  153.    ;
  154.  
  155.   fullname = maildir;                    // Build full filename.
  156.   strcat(fullname,fname);
  157.  
  158.   f=fopen(fullname,"r");                 // Open file,
  159.   if (f < 0) return (0);                 // check for error.
  160.  
  161. // Read these before starting to send mail.
  162.  
  163.   if (fgets(input,144,f) <0) goto error; // Read conference.
  164.   conf = input;
  165.   if (fgets(input,144,f) <0) goto error; // Read name.
  166.   towhom = input;
  167.   if (fgets(input,144,f) <0) goto error; // Read reference
  168.   reply = input;
  169.   if (fgets(input,144,f) <0) goto error; // Read subject.
  170.   subj = input;
  171.   if (fgets(input,144,f) <0) goto error; // Echo to other systems (Yes/no)
  172.   echo = input;
  173.   strcat (echo,"^M");                    // Add a CR.      
  174.   if (fgets(input,144,f) <0) goto error; // Read private (Yes/no)
  175.   priv = input;
  176.   goto OK;
  177.  
  178. error:
  179.   fclose(f);
  180.   fdelete (fullname);
  181.   return (0);
  182.  
  183. OK:
  184.   if (subchr(echo,0)=='Y')               // Answer to echo question
  185.     echo = "y^M";                        // must be Y
  186.   else                                   // or
  187.     echo = "n^M";                        // N.
  188.  
  189.   if (subchr(priv,0)=='Y')               // Private?
  190.     RO = 1;                              // Yes
  191.   else                                   // or
  192.     RO = 0;                              // No.
  193.  
  194.   if (call (Join,conf) < 0)              // Join conference.
  195.     return (0);                          // Return if error.
  196.   again = 0;
  197.  
  198. // Send the mail. Maildir contains directory, Filespec contains
  199. // wildcard name of the files to be uploaded.
  200.  
  201. enter:                                   // Start entering message.
  202.   WT = 1;                                // Wait time initially 1 sec.
  203.   if (reply == "0")  
  204.   { cputs("e ");
  205.     if (pcb)                             // PCBoard won't have
  206.     { cputs ("^M");                      // the name on the
  207.       help = ":";
  208.       if (PCBver>144) help="`ALL'?";
  209.       if (!waitfor (help,WT))
  210.         ++WT;                            // same line!
  211.       else if (WT > 2)
  212.         --WT;
  213.     }
  214.     cputs(towhom);
  215.   }
  216.   else
  217.   { cputs("reply ");                     // Answer to previous message.
  218.     cputs(reply);
  219.   }
  220.   cputs(